﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WxPayAPI;

namespace LPY.LeHealth.WebSite.Controllers
{
    //测试
    public class TestController : Controller
    {
        //
        // GET: /Test/
        public ActionResult Index()
        {
            //测试获取重定向目标Url地址
            HttpClientHelper hch = new HttpClientHelper();
            //string url = "http://zsl.s1.natapp.cc/" + "example/PrePay";
            string url = "http://localhost:39106/" + "test/ReDirect";
            var result= hch.checkUrlCanReached(url);
            return Content(result.RawUrl);
        }

        public ActionResult WeChat()
        {
            string redirect_uri = WxPayAPI.WxPayConfig.Domain + "example/PayCallBack";// HttpUtility.UrlEncode("http://" + host + path);//这是一个坑
            WxPayData data = new WxPayData();
            data.SetValue("appid", WxPayConfig.APPID);
            data.SetValue("redirect_uri", redirect_uri);
            data.SetValue("response_type", "code");
            data.SetValue("scope", "snsapi_base");
            data.SetValue("state", "STATE" /*+ "#wechat_redirect"*/);
            string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl();
            HttpClientHelper hch = new HttpClientHelper();
            var result = hch.checkUrlCanReached(url);
            return Content(result.RawUrl);
        }

        public ActionResult ReDirect()
        {
            string url="http://localhost:39106/"+"test/target";
            Response.Redirect(url);

            return Content("Test.Redirect");
        }

        public ActionResult Target()
        {
            return Content("Test.Target");
        }
	}
}